package com.merry.sb.config;

import com.baomidou.mybatisplus.core.MybatisSqlSessionFactoryBuilder;
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
import com.github.pagehelper.PageInterceptor;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;
import java.util.Properties;

@Configuration
public class MyBatisConfig {

    /**
     *
     * 由于我项目中没有引入 pageHelper的starter，所以需要在这里手动添加上一个拦截器。
     */
//    @Bean
//    public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
//        MybatisSqlSessionFactoryBean sqlSessionFactoryBean = new MybatisSqlSessionFactoryBean();
//        sqlSessionFactoryBean.setDataSource(dataSource);
//
//        // 省略其他配置，如添加MyBatis mapper文件等
//        sqlSessionFactoryBean.setMapperLocations();
//        // 添加PageInterceptor插件
//        PageInterceptor pageInterceptor = new PageInterceptor();
//        Properties properties = new Properties();
//        properties.setProperty("helperDialect", "mysql");
//        // 其他PageHelper属性配置
//        pageInterceptor.setProperties(properties);
//
//        // 添加插件
//        sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageInterceptor});
//
//        return sqlSessionFactoryBean.getObject();
//    }

}
